package com.abstralabs.time;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class TimeDatabase extends SQLiteOpenHelper {
	  
	  public static final String TABLE_NAME = "time";
	  public static final String COLUMN_ID = "_id";
	  public static final String COLUMN_ACT = "activity";
	  public static final String COLUMN_SEC = "seconds";
	  public static final String COLUMN_DAY = "day";

	  private static final String DATABASE_NAME = "time.db";
	  private static final int DATABASE_VERSION = 3;
	  
	  public static final String INT_TYPE = " INT";//" MEDIUMINT";
	  public static final String TEXT_TYPE = " TEXT";
	  public static final String COMMA = ", ";

	  private static final String DATABASE_CREATE =
	    "CREATE TABLE " + TABLE_NAME + "(" +
	    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
	    COLUMN_ACT + TEXT_TYPE + COMMA  +
	    COLUMN_SEC + INT_TYPE + COMMA + COLUMN_DAY + INT_TYPE +  " );";

		  public TimeDatabase(Context context) {
		    super(context, DATABASE_NAME, null, DATABASE_VERSION);
		  }

		  @Override
		  public void onCreate(SQLiteDatabase database) {
			//database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		    database.execSQL(DATABASE_CREATE);
		  }

		  @Override
		  public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		    Log.w(TimeDatabase.class.getName(),
		        "Upgrading database from version " + oldVersion + " to "
		            + newVersion + ", which will destroy all old data");
		    database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		    onCreate(database);
		  }

		} 
